<template>
  <div
    class="tool-bar"
    :class="activeTool === configData.handle ? 'active-tool-bar' : ''"
  >
    <div
      class="tools-icon"
      :style="{ backgroundColor: configData.backgroundColor }"
      @click="handleToolsBar(configData)"
    >
      <i :class="configData.icon"></i>
    </div>
    <div class="tools-title">{{ configData.name }}</div>
  </div>
</template>

<script>
import DxCommonUtils from "@/utils/cesiumDxUtils/common3D";

import { mapState } from "vuex";
export default {
  name: "ToolBar",
  props: {
    configData: {
      type: Object,
      default: () => {},
    },
  },
  computed: {
    ...mapState({
      isMeasure: (state) => state.user.isMeasure,
      isUndergroundModel: (state) => state.app.isUndergroundModel, // threejs 开启关闭
    }),
  },
  data() {
    return {
      activeTool: null,
      className: {},
    };
  },
  methods: {
    handleToolsBar(data) {
      if (data.handleType === "measureTool") {
        DxCommonUtils.handleMeasure[data.handle]();
        if (data.name === "坐标拾取") {
          this.activeTool =
            this.activeTool === data.handle ? null : data.handle;
          // document.addEventListener(
          //   "mousedown",
          //   function (event) {
          //     var btnNum = event.button;
          //     debugger;
          //   },
          //   false
          // );

          // document.onmousedown = (event) => {
          //   debugger;
          //   var event = event || window.event;
          //   if (event.button == "2") {
          //     this.activeTool = null;
          //   }
          // };
        }
      } else if (data.handleType === "analyseTool") {
        DxCommonUtils[data.handle]();
      } else if (data.handleType === "systemTool") {
        // DxCommonUtils[data.handle]();
        this.activeTool = this.activeTool === data.handle ? null : data.handle;
        this[data.handle]();
      }
    },
    // 透明地球
    handleTransparentEarth() {
      this.$store.commit(
        "app/updataUndergroundModel",
        !this.isUndergroundModel
      );
    },
  },
  watch: {
    isMeasure() {
      this.activeTool = null;
    },
  },
};
</script>

<style  lang="scss" scoped>
.tool-bar {
  width: 46%;
  height: 46%;
  margin: 2% 2%;
  box-sizing: border-box;
  cursor: pointer;
  padding: 2% 0;
  transition: all 0.6s;
  .tools-icon {
    width: 40px;
    height: 40px;
    margin: 0 auto;
    overflow: hidden;
    text-align: center;
    border: 1px solid transparent;
    border-radius: 50%;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    i {
      transition: all 0.6s;
      transform: scale(1);
    }
  }
  .tools-title {
    text-align: center;
    height: 20px;
    line-height: 20px;
  }
}
.tool-bar:hover,
.active-tool-bar {
  box-shadow: 0 0 4px #fff, 0 0 2px #fff inset;
  border-radius: 4px;
  .tools-icon {
    // font-size: 24px;
    i {
      transform: scale(2);
    }
  }
}
</style>